$(function(){
      var currentCity=SYS_GLOBAL_CONFIG.getCurrentCity("currentCity");
        //显示服务，商品，店铺菜单选择
        $(".search-center .center-span,.search-center .seacher-img").on("click",function(){
            $("#classify").toggle(100); 

        });  
        $(".c-ul li").on("click",function(){
            var links=$(this).find("a").attr("data-link");
            location.href="./"+links+".html?currentCity="+currentCity;
        });
    
        var url=SYS_GLOBAL_CONFIG.reqUrl,
        async="true",
        type="post";
        var address=currentCity;//获取当前城市
        var currentPage=1;//默认设置当前页为第一页
        var totalPage=1;//设置默认总页数
        var show_count=3;//设置默认每次加载的条数
        var dataProductNext="";
        var pdTypeId=parseInt(SYS_GLOBAL_CONFIG.getQueryString("pdTypeId"));
        var productTypeId=0;
        var requestData3="";
        var requestData=JSON.stringify({
            "code":"getPdOrServTypeList",
            "version":"1.0",
            "data":{
                "parentServiceId":0,
                "currentPage":currentPage,
                "address":address,
                "type":"PRODUCT",
                "parentPdTypeId":pdTypeId
            }
        });
        var requestData2=JSON.stringify({
                "code":"getShopList",
                "verson":"1.0",
                "data":{
                    "salesManId":"",
                    "address":address,
                    "sellerType":"",
                    "parentPdTypeId":pdTypeId,
                    "resType":"1",
                    "currentPage":currentPage,
                    "showCount":show_count
                 }
            });
        getData(url,requestData,handdle_func1,async,type);
        getData(url,requestData2,handdle_func2,async,type); 
        function getData(url,datas,call_func,async,type){
            console.log("请求参数:"+datas);
            $.ajax({
                url:url,
                type:type,
                datatype:"json",
                async:async,
                contentType:"application/json",
                data:datas,
                success:function(data){
                    call_func(data);
                },
                error:function(){
                    console.log("失败-----------");
                }   
            });        
        }       
        function handdle_func1(data){
            console.log(data);
            var list=data.data.productTypes;
            console.log(data.data.productTypes)
            var listLen=list.length;
            for(var i=0;i<listLen;i++){
                  var dataS='<li class="zwl-li cl333" data-productTypeId="'+list[i].pdTypeId+'">'+list[i].pdTypeName+'</li>';
                  $(".zwl-ul").append(dataS);
            }
            $(".zwl-li").on("click",function(){
                console.log("aaaa");
                $(this).addClass("bg36c8b8");
                $(this).siblings().removeClass("bg36c8b8");
                $("#detail").html("");
                productTypeId=$(this).attr("data-productTypeId");
                requestData3=JSON.stringify({
                       "code":"getShopList",
                       "version":"1.0",
                       "data":{"userId":"",
                               "productType":"",
                               "productName":"",
                               "shopId":"",
                               "currentPage":currentPage,
                               "showCount":show_count,
                               "productTypeId":productTypeId,
                               "parentPdTypeId":pdTypeId,
                               "address":address
                       }
                });  
            getData(url,requestData3,handdle_func2,async,type); 
                current_Page=1;
                $(window).scroll(function(){
                totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
                console.log((parseFloat($(document).height())-200)+"-------"+totalheight);
                $(".data-loading").removeClass("hide").addClass("show");
                    if((parseFloat($(document).height())-200)<=totalheight){ 
                        
                        console.log(totalPage+"---"+current_Page);
                        if(totalPage>current_Page){
                            current_Page+=1;
                            var data_p=JSON.stringify({
                            "code":"getShopList",
                            "verson":"1.0",
                                "data":{
                                "currentPage":current_Page,
                                "showCount":show_count,
                                "productTypeId":productTypeId,
                                "address":address
                            }
                        });
                        getData(url,data_p,handdle_func2,async,type);    
                        }else{
                            $(".data-loading").html("已加载全部");
                        }
                    } 
            });
     
            });
            
        }  
        
        function handdle_func2(data){
            console.log(data);
            var dataS=data.data.datas;
            var s_len=dataS.length;
            var img="";
            var registr="";
            var attr="";
            totalPage=data.data.totalPage;
            var li="";
            var downS='';
            for(var i=0;i<s_len;i++){
                if(dataS[i].seller){
                    if(dataS[i].seller.isSellerAuth=="1"){
                        img='<img class="img3" src="./images/vip_icon.png" alt="">';
                        registr="(已认证)";
                    }else{
                        img="";
                        registr="(未认证)";
                    }    
                }
                var tagStr='';
                var tagS='';
                if(dataS[i].sellerFees){
                    if(dataS[i].sellerFees.length>0){
                        console.log(dataS[i].sellerFees.length);
                        if(dataS[i].sellerFees.length>0){
                            var SellerFree=dataS[i].sellerFees[0].isAvaliable;
                            if(SellerFree=="1"){//已开通增值服务
                                var s_tag=dataS[i].tagServices;
                                var ss_len=s_tag.length;
                                if(ss_len>2){
                                    downS='<i class="down"></i>';
                                }
                                for(var s=0;s<ss_len;s++){
                                    tagStr+='<p class="tags_info"><img src="'+s_tag[s].tagIconPath+'" alt=""><span>'+s_tag[s].userRemark+'</span></p>';
                                    if(s<3){
                                        tagS+='<span>'+s_tag[s].name+'</span>';
                                    }
                                }        
                            }       
                        }
                    }    
                }

               li+='<div class="detail-shop" data-shopId="'+dataS[i].shopId+'">'+
                    ' <img class="img2" src="'+dataS[i].logoImgPath+'" alt="">'+
                    '<div class="introduce">'+
                    ' <div class="introduce-detail">'+
                    '<div class="introduce-name">'+
                    '<span class="span-detail"><span class="span-name">'+dataS[i].shopName+'</span>'+ 
                    ''+img+'</span><p class="span-tags">'+tagS+'</p>'+
                    ' <span class="cess r1">'+dataS[i].shopTypeName+'</span><span class="regstr r1">'+registr+'</span> </div>'+
                    '<div class="clears"></div></div></div><div class="clears"></div><div class="zwl-benefit max2_h">'+tagStr+downS+'</div></div>';
            }
            $("#detail").append(li);
            var down_flag=1;
            if(downS!=''){
                $(".zwl-benefit i").off("click");
                $(".zwl-benefit i").on("click",function(){
                    if(down_flag==1){  
                        $(this).addClass("up").removeClass("down").parent(".zwl-benefit").addClass("auto_h").removeClass("max2_h");
                        down_flag=0;
                    }else{
                        $(this).addClass("down").removeClass("up").parent(".zwl-benefit").addClass("max2_h").removeClass("auto_h");
                        down_flag=1;
                    }
                });    
            }
            $(".detail-shop .img2,.detail-shop .introduce").on("click",function(){
                var shopId =$(this).parent(".detail-shop").attr("data-shopId");
                url = "shopDetail.html?shopId="+shopId;//此处拼接内容
                location.href = url;
            });
   }
      var current_Page=1;
    /**
     *滚动加载更多*
     **/
    $(window).scroll(function(){
        totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop())-400;
        $(".data-loading").removeClass("hide").addClass("show");
        if((parseFloat($(document).height())-400)==totalheight){ 
            console.log(totalPage+"---"+current_Page);
            if(totalPage>current_Page){
                current_Page+=1;
                var data_p=JSON.stringify({
                "code":"getShopList",
                "verson":"1.0",
                    "data":{
                    "currentPage":current_Page,
                    "showCount":show_count,
                    "parentPdTypeId":pdTypeId,
//                    "productTypeId":productTypeId,
                    "address":address
                }
        });
                getData(url,data_p,handdle_func2,async,type);    
            }else{
                $(".data-loading").html("已加载全部");
            }
        } 
     });

});